package br.com.ecommerce.config;

import javax.annotation.PostConstruct;

import org.jboss.logging.Logger;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;

/**
 * @author marco.nascimento
 */
@Configuration
public class ApplicationConfig {
    
    private static Logger logger = Logger.getLogger("ecommerce");
    
    private static ResourceBundleMessageSource messages = new ResourceBundleMessageSource();
    
    @Bean(name = "logger")
    public Logger applicationLogger() {
        return logger;
    }
    
    @Bean(name = "messageSource")
    public MessageSource messageSource() {
        return messages;
    }
    
    @PostConstruct
    protected void initApplication() {
        logger.info("=== eCommerce CONFIG STARTED ===");
        logger.infof("===>>> Running on JVM in \"%s\"", System.getProperty("java.home"));
        
        messages.setBasename("messages");
        
        logger.info("===  SERTTUS CONFIG ENDED  ===");
    }
}